<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Departments;

class DepartmentController extends Controller
{
    public function index(Request $request)
    {
        $map = [];
        $request->name && $map['name'] = $request->name;

        return Departments::where($map)->orderBy('id')->paginate(10);
    }

    public function update(Request $request, $id)
    {
        $department = Departments::find($id);

        return response()->json($department->update($request->all()));
    }

    public function show($id)
    {
        return Departments::find($id);
    }

    public function store(Request $request)
    {
        $data = $request->all();
        return  Departments::create($data);
    }

    public function all()
    {
        return Departments::all();
    }

//    public function destroy($id)
//    {
//        $department = Departments::find($id);
//        $department && $department->delete();
//    }
}
